#include <xp/bas/locale.h>
#include <xp/bas/string.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>

int xp_main ()
{
	xp_mchar_t buf[100];
	xp_size_t n;

	xp_setlocale ();

	{
		const xp_wchar_t* wstr = XP_WTEXT("\uC720\uB2C8\uCF54\uB4DC");
		xp_mchar_t bufx[100];
		xp_size_t wstrlen = xp_strlen(wstr);
		unsigned int i;

		printf ("---------------\n");
		for (i = 0; i < 20 && i < xp_countof(bufx); i++) {
			xp_size_t bufsz = i;

			n = xp_wcsntomcs (wstr, wstrlen, bufx, &bufsz);
			printf ("buf[%u] ", i);

			if (n == -1) printf ("** conversion error **\n");
			else { 
				bufx[bufsz] = XP_MCHAR('\0');
				printf ("%lu/%lu bytes  %lu/%lu characters [%s]\n", 
					bufsz, xp_wcsnmclen(wstr, wstrlen), n, wstrlen, bufx);
			}
		}
	}

	return 0;

}

